package org.linys.dao.dict;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.linys.model.dict.City;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@SuppressWarnings("unchecked")
@Repository
public class CityDAO {
	private SqlSession sqlSession;
	@Autowired
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}
	
	public City selectTreeRoot() {
		return (City) sqlSession.selectOne("CityMapper.selectTreeRoot");
	}
	
	public List<City> selectTreeNode(City city) {
		return (List<City>) sqlSession.selectList("CityMapper.selectTreeNode",city);
	}


	public List<City> getTreeNodeTabel(City city, Integer offset,
			Integer limit) {
		return (List<City>) sqlSession.selectList("CityMapper.getTreeNodeTabel",city,new RowBounds(offset,limit));
	}

	public int save(City city) {
		return sqlSession.insert("CityMapper.insert", city);
	}

	public Integer insertValdate(City city) {
		return (Integer) sqlSession.selectOne("CityMapper.insertValdate",city);
	}

	public int deleteByCityID(Integer cityID) {
		return sqlSession.delete("CityMapper.deleteByCityID", cityID);
	}

	public int count(City city) {
		return (Integer) sqlSession.selectOne("CityMapper.count",city);
	}

	public int countChoose(City city) {
		return (Integer) sqlSession.selectOne("CityMapper.countChoose",city);
	}

	public List<City> viewChoose(City city, Integer start, Integer rows) {
		return (List<City>) sqlSession.selectList("CityMapper.viewChoose",city,new RowBounds(start,rows));
	}

	public int update(City city) {
		return sqlSession.update("CityMapper.update", city);
	}

}
